package com.cheng.im.service.friendship.controller;

import com.cheng.im.service.common.resp.CommonResult;
import com.cheng.im.service.friendship.service.ImFriendshipRequestService;
import com.cheng.im.service.frienship.domain.ImFriendshipRequest;
import com.cheng.im.service.frienship.model.req.ApproverFriendRequestReq;
import com.cheng.im.service.frienship.model.req.GetFriendShipRequestReq;
import com.cheng.im.service.frienship.model.req.ReadFriendShipRequestReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * todo: 接口还没测
 */
@Api(tags = "好友申请")
@RestController
@RequestMapping("v1/friendshipRequest")
public class ImFriendshipRequestController {

    @Resource
    private ImFriendshipRequestService imFriendshipRequestService;

    /**
     * 好友申请处理
     * operator是执行者
     * @param req
     * @return
     */
    @ApiOperation(value = "好友申请处理", notes = "")
    @PostMapping("/approveFriendRequest")
    public CommonResult approveFriendRequest(@RequestBody @Validated ApproverFriendRequestReq req){
        return imFriendshipRequestService.approveFriendRequest(req);
    }

    /**
     * 获取好友申请列表
     * @param req
     * @return
     */
    @ApiOperation(value = "好友申请列表", notes = "")
    @PostMapping("/getFriendRequest")
    public CommonResult<List<ImFriendshipRequest>> getFriendRequest(@RequestBody @Validated GetFriendShipRequestReq req){
        return imFriendshipRequestService.getFriendRequest(req.getFromId(), req.getAppId());
    }

    /**
     * 更新已读
     * @param req
     * @return
     */
    @PutMapping("/readFriendShipRequestReq")
    @ApiOperation(value = "好友申请已读更新", notes = "")
    public CommonResult readFriendShipRequestReq(@RequestBody @Validated ReadFriendShipRequestReq req){
        return imFriendshipRequestService.readFriendShipRequestReq(req);
    }
}
